package com.enfry.common.util.excel;

import java.util.ArrayList;
import java.util.List;

import org.jdom.Element;

public class TR extends Cell {

	private static final long serialVersionUID = -2160925506179018181L;
	private List<TD> tds = new ArrayList<TD>();

	@Override
	public int getWidth() {
		int width = 0;
		for (int i = 0; i < this.tds.size(); i++) {
			width += (this.tds.get(i)).getWidth();
		}
		return width;
	}

	@Override
	public int getHight() {
		return 1;
	}

	public void addTD(TD td) {
		this.tds.add(td);
		td.parent = this;
	}

	public TD getTD(int index) {
		return this.tds.get(index);
	}
	
	public List<TD> getTds() {
		return tds;
	}

	public void setTds(List<TD> tds) {
		this.tds = tds;
	}

	public static TR load(Element element) throws Exception {
		TR tr = new TR();
		List subs = element.getChildren("td");
		if ((subs != null) && (subs.size() > 0)) {
			for (int i = 0; i < subs.size(); i++) {
				tr.addTD(TD.load((Element) subs.get(i)));
			}
		}
		return tr;
	}

}
